package com.tuyrt.unit2

import java.util.*

/**
 * Created by tuyrt7 on 2021/1/13.
 *  集合 listOf mutableListOf \ mapOf mutableMapOf
 */

/**
listOf(): 不可变
mutableListOf(): 可变
 */
val list = listOf("hello", "world", "wo shi hao ren")
val list2 = mutableListOf("hello", "world")
val map = mapOf("hello" to 1, "world" to 2)
val map2 = mutableMapOf("hello" to 1, "world" to 1)

fun main() {
    hello()

    list2.add("dageda")

    //取值、赋值
    val value = map2["hello"]
    map2["world"] = 3
}

fun hello(): Unit {
    for (s in list) {
        println("你好：${s}")
    }

    for ((key, value) in map) {
        println("key is $key , value is $value")
    }

    // 取元素长度，最大值
    list.maxByOrNull { it.length }

    //map 映射
    list.map { it.toUpperCase() }

    //过滤
    list.filter { it.length < 5 }

    // any 、 all (集合中是否只有 至少
    // 至少一个\所有 都满足条件)
    list.any { it.length < 5 }
    list.all { it.length < 5 }

}


